/*!
* @author @huntbao
* @dialog helpers
*/
App.modalHelper = {
    showNormalModal: function(config){
        var self = this;
        var result = $(Mustache.to_html(tpl.noramlModal, {
           title: App.i18n.get(config.title),
           ladingTip: App.i18n.get('loadingTip'),
           ok: App.i18n.get('ok'),
           cancel: App.i18n.get('cancel')
        }));
        if(config.modalClass){
            result.addClass(config.modalClass);
        }
        var modal = (config.modalContainer ? config.modalContainer : $("#dialog")).html(result),
        normalModal = modal.find(".normal-modal"),
        modalBody = normalModal.find('.body-inner'),
        okBtn = normalModal.find('.btn-ok'),
        loadingTip = normalModal.find('.loading-tip'),
        cancelBtn = normalModal.find('.btn-cancel');
        normalModal.modal({
            keyboard: true,
            show: true,
            backdrop: _.isUndefined(config.backdrop) ? 'static' : config.backdrop
        }).draggable({
            containment: 'window',
            handle: '.modal-header'
        });
        if(config.style){
            result.css(config.style);
        }else{
            result.css({
               left: ($(window).width() - result.width()) / 2,
               top: 150
            });
        }
        if(config.button === null){
            normalModal.find('.modal-footer').hide();
        }else if(_.isObject(config.button)){
            if(_.isString(config.button.ok)){
                okBtn.text(App.i18n.get(config.button.ok))
            }else{
                okBtn.hide();
            }
            if(_.isString(config.button.cancel)){
                cancelBtn.text(App.i18n.get(config.button.cancel))
            }else{
                cancelBtn.hide();
            }
        }
        if(config.url){
            $.ajax({
                url: config.url,
                dataType: 'text',
                cache: false
            }).done(function(data){
                config.done(data, modalBody, okBtn, normalModal);
            });
            return self;
        }
        config.done(null, modalBody, okBtn, normalModal);
    }
}
